<script>
import { defineComponent } from "vue";
import {pageHandler} from '@/mixins/pageHandler'
import RightClickmenuList from "@/components/rightClickmenuList/rightClickMenuList.vue";
import YaokongDialog from "@/components/rightClickmenuList/yaokongDialog.vue";
import GuapaiDialog from "@/components/rightClickmenuList/guapaiDialog.vue";
import ScaleBox from "@/components/ScaleBox/ScaleBox.vue";
import MonitorHeader from "@/components/MonitorHeader/MonitorHeader.vue";
import NetState from "@/components/controls/netState.vue";
import ConnectLine from "@/components/controls/connect-line.vue";
import TerminalSvg from "@/components/controls/terminal-svg.vue";
import RectSvg from "@/components/controls/rect-svg.vue";
import ShouCheSvg from "@/components/controls/shou-che-svg.vue";
import KongZhiBaShou from "@/components/controls/KongZhiBaShou.vue";
import YingYaBan from "@/components/controls/YingYaBan.vue";
import GuangZiPai from "@/components/controls/GuangZiPai.vue";
import Zhanyongbian from "@/components/controls/zhanyongbian.vue";

export default defineComponent({
  name: "zhubian",
  components: {
      Zhanyongbian,
      GuangZiPai, YingYaBan, KongZhiBaShou, ShouCheSvg, RectSvg, TerminalSvg, ConnectLine, NetState, MonitorHeader, ScaleBox, GuapaiDialog, YaokongDialog, RightClickmenuList },
  mixins: [pageHandler],
  data() {
    return {
      hardPlatenDataList: [],
      flexiblePlatenDataList: [],
      GZPDataList: [],
      netStateList: [],
      numList:[],
      bashouList:[],
      svgYaban:[],
    };
  },
  methods:{
    initData(e){
      const typeMap = {
        "压板": "hardPlatenDataList",
        "网络状态": "netStateList",
        "遥测":'numList',
        "操作把手":"bashouList",
          '保护信号':'GZPDataList',
      };

      for (const listName of Object.values(typeMap)) {
        this[listName] = [];
      }
      for (const [key, value] of Object.entries(e)) {
        for (const [type, listName] of Object.entries(typeMap)) {
          const filtered = value.filter(item => item.type === type);
          if (filtered.length > 0) {
            this[listName].push({ name: key, list: filtered });
          }
        }
      }
    },
  }
});
</script>

<template>
  <div class="breaker-graph" @click="cancelLeftClickMenu" @contextmenu.stop="cancelLeftClickMenu" v-if="pageData">
    <scale-box :width="1920">
      <MonitorHeader :title="$route.query.ftName" >
        <template v-slot:btns>
          <button @click="routerToMainPage">主接线图</button>
          <button @click="clearAll($route.query.ftName)">画面清闪</button>
          <button @click="operationRecords">操作记录</button>
        </template>
      </MonitorHeader>
      <main>
      <div>
          <div class="line-wrapper">
              <svg>
                  <g>
                      <line x1="220" y1="375" x2="620" y2="375" stroke="rgb(255,255,0)" stroke-width="5"></line>
                      <line x1="220" y1="775" x2="620" y2="775" stroke="rgb(0,210,0)" stroke-width="5"></line>
                      <line x1="420" y1="375" x2="420" y2="400" stroke="rgb(255,255,0)" stroke-width="2"></line>
                      <text x="420" y="355" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">35kV 2母</text>
                      <text x="420" y="800" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">10kV 2母</text>
                      <text x="320" y="500" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">2号主变</text>
                      <g v-for="(item,index) in pageData['1M']" transform="translate(100,0)">
                          <text x="420" :y="405+index*30" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">{{item.state_desc}}</text></text>
                          <text x="480" :y="405+index*30" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">{{item.state_val}}</text>
                      </g>
                      <g v-for="(item,index) in pageData['2M']" transform="translate(100,260)">
                          <text x="420" :y="405+index*30" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">{{item.state_desc}}</text></text>
                          <text x="480" :y="405+index*30" style="fill: rgb(255,255,255);font-size: 20px;font-weight: normal">{{item.state_val}}</text>
                      </g>
                      <connect-line
                              :state="Number(pageData['glg'][0].state_val)"
                              :stateDesc="pageData['glg'][0].state_desc"
                              :scale="0.8"
                              :rotate="-90"
                              :info="pageData['glg'][0]"
                              :translate-x="388"
                              :translate-y="436"
                              :text-translate-y="0"
                              :text-translate-x="-10"
                              @itemRightClick="itemRightClick"
                              :name="pageData['glg'][0].state_desc"></connect-line>
                      <line x1="420" y1="440" x2="420" y2="470" stroke="rgb(255,255,0)" stroke-width="2"></line>
                      <zhanyongbian color="rgb(255,255,0)" color_1="rgb(0,210,0)" :rotate="180" :translate-x="-660" :translate-y="-294"></zhanyongbian>
                      <line x1="420" y1="526" x2="420" y2="560" stroke="rgb(0,210,0)" stroke-width="2"></line>
                      <rect-svg
                              :state="Number(pageData['dlq'][0].state_val)"
                              :stateDesc="pageData['dlq'][0].state_desc"
                              :rotate="90"
                              :translate-y="558"
                              :translate-x="461"
                              :info="pageData['dlq'][0]"
                              :text-translate-x="-60"
                              :text-translate-y="-4"
                              :scale="1"
                              @itemRightClick="itemRightClick"
                              :itemObj="{is_clear:pageData['dlq'][0].is_clear}"
                              :name="pageData['dlq'][0].state_desc"
                      ></rect-svg>
                      <line x1="420" y1="596" x2="420" y2="775" stroke="rgb(0,210,0)" stroke-width="2"></line>
                      <shou-che-svg
                              :shou-che-data-obj="pageData['sc'][0]"
                              :rotate="90" :translate-x="460" :translate-y="655" :title-x="-25" :title-y="-10" :name="pageData['sc'][0].state_desc"
                              :sc-gap="12"
                      ></shou-che-svg>
                  </g>
              </svg>
          </div>
      </div>
      <div>
          <div class="gzpBox">
              <div class="gzpInner"  v-for="o in this.GZPDataList">
                  <div style="text-align: center;font-size: 1.6rem;color: rgb(220, 214, 147);margin: 1rem 0">{{o.name}}</div>
                  <div class="gzpItem">
                      <div v-for="item in o.list">
                          <GuangZiPai :set-hei="true" height="26" :info="item" :isClear="+item.is_clear" :jianGeMing="item.jg_name" :name="item.state_desc" :state="Number(item.state_val)"></GuangZiPai>
                      </div>
                  </div>
              </div>

          </div>
      </div>
      </main>
    </scale-box>
  <rightClickmenuList v-if="rightMenuObj&&showMenu" :rightMenuObj="rightMenuObj" @menuItemClick="menuItemClick"></rightClickmenuList>
  <el-dialog  custom-class="yaokongPersonDialog" :visible.sync="operatorPwdDialogVisible_0" width="22%" :close-on-click-modal="false">
    <p slot="title" class="el-dialog__title">操作人</p>
    <div class="operatorPwd">
      <div class="operator">
        <label>请输入操作人</label>
        <el-select size="small" v-model="operatorPwdObj.username" style="width: 16rem;">
          <el-option
            v-for="(item,index) in userInfoJson.operatorList"
            :key="index"
            :label="item.username"
            :value="item.username"
          ></el-option>
        </el-select>
      </div>
      <div class="pwd">
        <label>请输入密码</label>
        <el-input v-model="operatorPwdObj.pwd" size="small" type="password"   @keydown.enter.native="operatorPwdSubmit_0"></el-input>
      </div>
    </div>
    <span slot="footer" class="dialog-footer" >
				<el-button size="small" @click="operatorPwdSubmit_0">确 定</el-button>
				<el-button size="small" @click="operatorPwdDialogVisible_0 = false">取 消</el-button>
			</span>
  </el-dialog>
  <el-dialog  custom-class="yaokongPersonDialog" :visible.sync="operatorPwdDialogVisible" width="22%" :close-on-click-modal="false">
    <p slot="title" class="el-dialog__title">监护人</p>
    <div class="operatorPwd">
      <div class="operator">
        <label>请输入监护人</label>
        <el-select size="small" v-model="adminPwdObj.username" style="width: 16rem;">
          <el-option
            v-for="(item,index) in userInfoJson.adminList"
            :key="index"
            :label="item.username"
            :value="item.username"
          ></el-option>
        </el-select>

      </div>
      <div class="pwd">
        <label>请输入监护员密码</label>
        <el-input v-model="adminPwdObj.pwd" size="small" type="password" @keydown.enter.native="operatorPwdSubmit"></el-input>
      </div>
    </div>
    <span slot="footer" class="dialog-footer" >
				<el-button size="small" @click="operatorPwdSubmit">确 定</el-button>
				<el-button size="small" @click="operatorPwdDialogVisible = false">取 消</el-button>
			</span>
  </el-dialog>
  <el-dialog
    custom-class="switchPatrolDialog"
    :visible.sync="dialogVisible"
    :close-on-press-escape="true"
    :close-on-click-modal="true"
    :width="`40%`"
    :modal="false"
    @before-close="handleDialogClose"
  >

    <!-- 隔离刀 -->
    <template v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.type == 'gelidao'">

      <!-- 遥控 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 1">
        <p slot="title" class="el-dialog__title">遥控</p>
        <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj" :text="yaokongMsg"></yaokongDialog>
      </template>

      <!-- 开关清闪 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 2">
        <p slot="title" class="el-dialog__title">开关清闪</p>
      </template>



      <!-- 挂牌/摘牌 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 6">
        <p slot="title" class="el-dialog__title">挂牌/摘牌</p>
        <guapaiDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></guapaiDialog>
      </template>

      <span slot="footer" class="dialog-footer" >
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value != 4" size="small" @click="dialogVisible = false">取 消</el-button>

        <!-- 遥控 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&!canyaoKong" size="small" @click="yaokongSelect">遥控选择</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&canyaoKong" size="small" @click="remoteControlSelect">遥控执行</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1" size="small" type="primary" plain @click="dialogVisible = false">关 闭</el-button>
        <!-- 挂牌/摘牌 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 6" size="small" type="primary" @click="handleBrand">确 定</el-button>

				</span>
    </template>

    <!-- 地刀 -->
    <template v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.type == 'didao'">
      <!--          遥控-->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 1">
        <p slot="title" class="el-dialog__title">遥控</p>
        <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj" :text="yaokongMsg"></yaokongDialog>
      </template>
      <!-- 开关清闪 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 0">
        <p slot="title" class="el-dialog__title">开关清闪</p>
        <span>暂无内容</span>
      </template>

      <!-- 全站清闪 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 4">
        <p slot="title" class="el-dialog__title">全站清闪</p>
        <span>暂无内容</span>
        <!-- <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></yaokongDialog> -->
      </template>
      <!-- 挂牌/摘牌 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 5">
        <p slot="title" class="el-dialog__title">挂牌/摘牌</p>
        <guapaiDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></guapaiDialog>
      </template>
      <span slot="footer" class="dialog-footer" >
            <!-- 遥控 按钮 -->					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 0" size="small" @click="dialogVisible = false">取 消</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&!canyaoKong" size="small" @click="yaokongSelect">遥控选择</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&canyaoKong" size="small" @click="remoteControlSelect">遥控执行</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1" size="small" type="primary" plain @click="dialogVisible = false">关 闭</el-button>


        <!-- 挂牌/摘牌 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 5" size="small" type="primary" @click="handleBrand">确 定</el-button>
				</span>
    </template>

    <!-- 断路器 -->
    <template v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.type == 'duanluqi'">
      <!-- 遥控 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 1">
        <p slot="title" class="el-dialog__title">遥控</p>
        <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj" :text="yaokongMsg"></yaokongDialog>
      </template>
      <!-- 开关清闪 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 2">
        <p slot="title" class="el-dialog__title">开关清闪</p>
        <span>确定要将{{currentSelectMenuItemObj.currentObj.name}}开关清闪吗？</span>
        <!-- <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></yaokongDialog> -->
      </template>
      <!-- 全站清闪 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 3">
        <p slot="title" class="el-dialog__title">全站清闪</p>
        <span>确定要将全部设备进行清闪吗？</span>
        <!-- <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></yaokongDialog> -->
      </template>

      <!-- 挂牌/摘牌 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 6">
        <p slot="title" class="el-dialog__title">挂牌/摘牌</p>
        <guapaiDialog :currentSelectMenuItemObj="currentSelectMenuItemObj"></guapaiDialog>
      </template>
      <span slot="footer" class="dialog-footer" >
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value != 4" size="small" @click="dialogVisible = false">取 消</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 2" size="small" @click="clearFlesh">确定</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 3" size="small" @click="clearAll">确定</el-button>
        <!-- 遥控 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&!canyaoKong" size="small" @click="yaokongSelect">遥控选择</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&canyaoKong" size="small" @click="remoteControlSelect">遥控执行</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1" size="small" type="primary" plain @click="dialogVisible = false">关 闭</el-button>

        <!-- 挂牌/摘牌 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 6" size="small" type="primary" @click="handleBrand">确 定</el-button>
				</span>
    </template>

    <!-- 把手 -->
    <template v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.type == 'bashou'">
      <!-- 操作 - 弹框 -->
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 1">
        <p slot="title" class="el-dialog__title">操作</p>
        <span>暂无内容</span>
      </template>
      <span slot="footer" class="dialog-footer" >
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value != 2" size="small" @click="dialogVisible = false">取 消</el-button>

				</span>
    </template>



    <template v-if="currentSelectMenuItemObj&&currentSelectMenuItemObj.type=='ruanyaban'">
      <template v-if="currentSelectMenuItemObj.currentSelectItem.value == 1">
        <p slot="title" class="el-dialog__title">遥控</p>
        <yaokongDialog :currentSelectMenuItemObj="currentSelectMenuItemObj" :text="yaokongMsg"></yaokongDialog>
      </template>
      <span slot="footer" class="dialog-footer" >
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 2" size="small" @click="dialogVisible = false">取 消</el-button>

        <!-- 遥控 按钮 -->
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&!canyaoKong" size="small" @click="yaokongSelect">遥控选择</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1&&canyaoKong" size="small" @click="remoteControlSelect">遥控执行</el-button>
					<el-button v-if="currentSelectMenuItemObj && currentSelectMenuItemObj.currentSelectItem.value == 1" size="small" type="primary" plain @click="dialogVisible = false">关 闭</el-button>
				</span>
    </template>




  </el-dialog>
  <el-dialog ref="operateRecordDialogRef" custom-class="operateRecordDialog" :modal="false" :close-on-click-modal="false" v-if="operationRecordsDialogVisible" :visible.sync="operationRecordsDialogVisible" v-dialogDrag:{dialogDrag}="true" width="35%">
    <p slot="title" class="el-dialog__title">操作记录</p>
    <div class="messageAlarmList">
      <el-table :data="operationRecordsData" width="100%" height="250" >
        <el-table-column prop="num" label="序号" width="85" header-align="center" align="center" >
          <template #default="{row}">
            <span :class="{'is-highlight': !!row.isHighlight}">{{row.num}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="操作时间" width="160" header-align="center" align="center" >
          <template #default="{row}">
            <span :class="{'is-highlight': !!row.isHighlight}">{{row.createTime}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="log_desc" label="操作描述" header-align="center" >
          <template #default="{row}">
            <span :class="{'is-highlight': !!row.isHighlight}">{{row.log_desc}}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</div>
</template>

<style scoped lang="less">
@import "@/assets/css/public";
main {
  height: calc(100% - 90px);
  display: flex;
  flex-direction:row;
  justify-content: space-between;
  color: #FFFFFF;
  align-items: center;
  border: 1px solid white;
  & > div {
    border: 1px solid white;
    &:nth-of-type(1) {
      width: 48%;
      height: 98%;
    }
    &:nth-of-type(2) {
      width: 48%;
      height: 98%;
    }

  }
}
.gzpInner{
  height: 100%;
  padding: 10px;
  width: 40%;
  margin: 0 auto;
  .gzpItem{
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    width: 100%;
    height: 80%;
    overflow-y: auto;
    .gzpTitle{
      font-size: 22px;
      color: rgba(153, 82, 61);
      text-align: center;
    }
  }
}
.line-wrapper {
  border: 1px solid red;
  height: 900px;
  padding: 10px 0;
  box-sizing: border-box;
  svg {
    width: 100%;
    height: 100%;
  }
}
</style>
